<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>execstr</title>
  </head>
  <body bgcolor="#FFFFFF">
    <center>Scilab Function</center>
    <div align="right">Last update : 12/09/2006</div>
    <p>
      <b>execstr</b> -  execute Scilab code in strings</p>
    <h3>
      <font color="blue">Calling Sequence</font>
    </h3>
    <dl>
      <dd>
        <tt>execstr(instr)  </tt>
      </dd>
      <dd>
        <tt>ierr=execstr(instr,'errcatch' [,msg])  </tt>
      </dd>
    </dl>
    <h3>
      <font color="blue">Parameters</font>
    </h3>
    <ul>
      <li>
        <tt>
          <b>instr</b>
        </tt>: vector of character strings, Scilab instruction to be executed.</li>
      <li>
        <tt>
          <b>ierr</b>
        </tt>: integer, 0 or error number.</li>
      <li>
        <tt>
          <b>msg</b>
        </tt>: character string with values <tt>
          <b>'m'</b>
        </tt> or <tt>
          <b>'n'</b>
        </tt>.  Default value is <tt>
          <b>'n'</b>
        </tt>.</li>
    </ul>
    <h3>
      <font color="blue">Description</font>
    </h3>
    <p>Executes the Scilab instructions given in argument
      <tt>
        <b>instr</b>
      </tt>.</p>
    <p>Note that instr should not make use of continuation marks (..) </p>
    <p></p>
    <p>If the 'errcatch' flag is not present, error handling works as usual.</p>
    <p>If the 'errcatch' flag is set, and an error is encountered while
      executing the instructions defined in <tt>
        <b>instr</b>
      </tt>, <tt>
        <b>execstr</b>
      </tt>
      issues no error message, but aborts execution of the <tt>
        <b>instr</b>
      </tt>
      instructions (at the point where the error occurred), and resumes with
      <tt>
        <b>ierr</b>
      </tt> equal to the error number.  In this case the display of the
      error message is controlled by the <tt>
        <b>msg</b>
      </tt> option:</p>
    <dl>
      <dd>
        <b>"m"</b>: error message is displayed and recorded.</dd>
      <dd>
        <b>"n"</b>: no error message is displayed, but the error message is recorded (see <tt>
          <b>lasterror</b>
        </tt>).  This is the default.</dd>
    </dl>
    <p> ierr=execstr(instr,'errcatch') can handle syntactical errors. This is
      useful for evalution of instruction obtained by a query to the user.</p>
    <h3>
      <font color="blue">Examples</font>
    </h3>
    <pre>

execstr('a=1') // sets a=1.
execstr('1+1') // does nothing (while evstr('1+1') returns 2)

execstr(['if %t then';
         '  a=1';
         '  b=a+1';
         'else'
         ' b=0'
         'end'])

execstr('a=zzzzzzz','errcatch')
execstr('a=zzzzzzz','errcatch','m')

//syntax errors
execstr('a=1?02','errcatch')
lasterror(%t)

execstr('a=[1 2 3)','errcatch')
lasterror(%t)

 
  </pre>
    <h3>
      <font color="blue">See Also</font>
    </h3>
    <p>
      <a href="evstr.htm">
        <tt>
          <b>evstr</b>
        </tt>
      </a>,&nbsp;&nbsp;<a href="lasterror.htm">
        <tt>
          <b>lasterror</b>
        </tt>
      </a>,&nbsp;&nbsp;<a href="error.htm">
        <tt>
          <b>error</b>
        </tt>
      </a>,&nbsp;&nbsp;<a href="try.htm">
        <tt>
          <b>try</b>
        </tt>
      </a>,&nbsp;&nbsp;</p>
  </body>
</html>
